import std.stdio: writef,writefln;
//import std.math;

import Student;
import Perceptron;

void genStudents(inout Student[] s){
//(imie, jestDobrymStudentem, dobrzeSieUczy, chodziNaWyklady, pije, pali, przeklina, grzecznyNaMiescie, chodziSpacPoDobranocce)
 s ~= new Student("Karol",	-1,	-1,	1,	1,	-1,	-1,	-1,	-1);
 s ~= new Student("Wojtek",	1,	1,	1,	1,	-1,	-1,	-1,	-1);
 s ~= new Student("Marcin",	-1,	-1,	1,	-1,	1,	1,	-1,	-1);
 s ~= new Student("Robert",	1,	-1,	1,	1,	-1,	-1,	-1,	1);
 s ~= new Student("Franciszek",	-1,	-1,	-1,	-1,	-1,	1,	-1,	1);
 s ~= new Student("Dawid",	1,	-1,	1,	-1,	-1,	-1,	1,	1);
 s ~= new Student("Adrian",	-1,	-1,	-1,	1,	1,	-1,	1,	-1);
 s ~= new Student("Antoni",	1,	1,	-1,	1,	1,	-1,	1,	-1);
 s ~= new Student("Bartosz",	1,	1,	1,	-1,	1,	1,	1,	-1);
 s ~= new Student("Barbara",	-1,	-1,	-1,	1,	-1,	1,	-1,	-1);
 s ~= new Student("Aneta",	1,	-1,	1,	1,	-1,	-1,	1,	1);
 s ~= new Student("Ania",	1,	1,	1,	1,	1,	-1,	1,	-1);
 s ~= new Student("Julia",	1,	1,	1,	-1,	1,	1,	1,	-1);
 s ~= new Student("Marta",	-1,	-1,	-1,	1,	1,	-1,	-1,	-1);
 s ~= new Student("Jolanta",	1,	1,	1,	-1,	-1,	-1,	-1,	1);
 s ~= new Student("Olga",	-1,	-1,	1,	1,	-1,	-1,	-1,	-1);
 s ~= new Student("Zuzanna",	-1,	-1,	-1,	1,	-1,	1,	-1,	-1);
 s ~= new Student("Kasia",	-1,	-1,	1,	1,	1,	1,	-1,	-1);
 s ~= new Student("Tomasz",	1,	1,	1,	1,	1,	1,	1,	1);
 s ~= new Student("Piotr",	1,	1,	-1,	-1,	1,	-1,	1,	-1);
 s ~= new Student("Pawel",	-1,	-1,	-1,	-1,	-1,	1,	-1,	1);
 s ~= new Student("Kacper",	1,	-1,	1,	1,	1,	-1,	1,	1);
 s ~= new Student("Jan",	1,	1,	1,	-1,	1,	-1,	-1,	1);
 s ~= new Student("Benedykt",	1,	1,	-1,	1,	-1,	1,	1,	1);
 s ~= new Student("Krystian",	1,	-1,	1,	-1,	-1,	1,	1,	1);
 s ~= new Student("Slawomir",	-1,	-1,	-1,	-1,	-1,	1,	-1,	-1);
 s ~= new Student("Jaroslaw",	-1,	-1,	1,	-1,	1,	1,	-1,	-1);
 s ~= new Student("Lech",	1,	1,	1,	-1,	1,	1,	1,	-1);
 s ~= new Student("Hanna",	1,	1,	1,	-1,	-1,	-1,	1,	1);
 s ~= new Student("Julita",	1,	1,	-1,	-1,	1,	1,	-1,	1);
 s ~= new Student("Genowefa",	1,	1,	-1,	-1,	1,	-1,	1,	-1);
 s ~= new Student("Ala",	-1,	1,	-1,	1,	1,	1,	-1,	-1);
 s ~= new Student("Milosz",	1,	1,	1,	-1,	1,	-1,	1,	-1);
 s ~= new Student("Zbyszka",	1,	1,	1,	1,	1,	1,	1,	1);
 s ~= new Student("Andrzej",	1,	1,	-1,	1,	1,	-1,	1,	-1);


}

void train(inout Perceptron perc, Student[] students){

	for(int i = 0; i < 100; i++)
	foreach(s; students)
		perc.train(s.array, s.jestDobrymStudentem);
	
	perc.endTraining();
}

void main() {
	Student[] students;
	Perceptron perceptron;
	Student nowy = new Student("Nowy", 0, 1, -1, 1, 1, 1, -1, -1);
	int key;
	bool mainKey = false;

	genStudents(students);
	assert(students.length > 0);
	perceptron = new Perceptron(students[0].array.length);
	foreach(s;students)
		writefln(s.imie,":",s.array);
	train(perceptron, students);
//////
	nowy.jestDobrymStudentem = perceptron.detect(nowy.array);
	writefln("Nowy(",nowy.jestDobrymStudentem,"): ", nowy.array);
	writef("Nowy jest ");
	if(nowy.jestDobrymStudentem)
		writef("dobrym studentem bo:");
	else
		writef("zlym studentem bo:");
	while(!mainKey){
		key = perceptron.key(nowy.jestDobrymStudentem, nowy.array);
		if(key < 0)
			break;
		if(nowy.array[key] == 1)
			writef(nowy.cechy[key].nameP);
		else
			writef(nowy.cechy[key].nameN);
		mainKey = perceptron.mainKey(key);
		if(!mainKey)
			writef(" oraz ");
		perceptron.delKey(key, nowy.array);
	}
	writefln();
}
